package com.metadata_system.common.db.mapper;

import com.metadata_system.common.db.entity.Database;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

public interface DatabaseMapper extends Mapper<Database> {
    @Update("UPDATE md_database " +
            "SET project_total = (SELECT COUNT(*) FROM md_project WHERE database_id = #{id}) " +
            "WHERE id = #{id}")
    void updateProjectTotal(@Param("id") Integer id);

    @Update("UPDATE md_database " +
            "SET project_total = (SELECT IFNULL(SUM(data_total),0) FROM md_project WHERE database_id = #{id}) " +
            "WHERE id = #{id}")
    void updateDataTotal(@Param("id") Integer id);

    @Select("select last_insert_id()")
    Integer getLastInsertId();
}